from sklearn.metrics import confusion_matrix,accuracy_score,precision_score,recall_score,f1_score
import pandas as pd


# 真实值
y_true = ['恶性','恶性','恶性','恶性','恶性','恶性','良性','良性','良性','良性']
# 预测值
y_predict_A = ['恶性','恶性','恶性','良性','良性','良性','良性','良性','良性','良性']
y_predict_B = ['恶性','恶性','恶性','恶性','恶性','恶性','恶性','恶性','恶性','良性']

# 构建混淆矩阵
m_A=confusion_matrix(y_true,y_predict_A,labels=['恶性','良性'])
# print(m_A)
print(pd.DataFrame(data=m_A, columns=['恶性', '良性'], index=['恶性', '良性']))
m_B=confusion_matrix(y_true,y_predict_B,labels=['恶性','良性'])
# print(m_B)
print(pd.DataFrame(data=m_B, columns=['恶性', '良性'], index=['恶性', '良性']))

# 准确率
print('*'*80)
print(accuracy_score(y_true, y_predict_A))
print(accuracy_score(y_true, y_predict_B))


# 精确率
print('*'*80)
print(precision_score(y_true, y_predict_A, pos_label='恶性'))
print(precision_score(y_true, y_predict_B, pos_label='恶性'))

# 召回率
print("*"*80)
print(recall_score(y_true, y_predict_A, pos_label='恶性'))
print(recall_score(y_true, y_predict_B, pos_label='恶性'))


# F1-score
print('*'*80)
print(f1_score(y_true, y_predict_A, pos_label='恶性'))
print(f1_score(y_true, y_predict_B, pos_label='恶性'))
